package cn.yunhe.action;

import cn.yunhe.entity.User;
import cn.yunhe.services.LoginService;
import cn.yunhe.util.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import lombok.Data;

@Data
public class LoginAction extends BaseAction implements ModelDriven {
    private User user;
    private String repassword;
    /**
     * 用户登录
     *
     * @return
     */
    public String login() {
        LoginService loginService = new LoginService();
        User userLogin = loginService.login(user);
        if (userLogin != null) {
            getSession().setAttribute("user", userLogin);
            return SUCCESS;
        } else {
            return INPUT;
        }
    }

    /**
     * 用户注册
     *
     * @return
     */
    public String reg() {
        LoginService loginService = new LoginService();
        int flag = loginService.reg(user);
        if (flag > 0) {
            return "Login";
        } else {
            return "reg";
        }
    }

    @Override
    public Object getModel() {
        if (user == null) {
            user = new User();
        }
        return user;
    }
}
